package org.cable.log;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListAdapter extends BaseAdapter{
	private ArrayList<Music> arr;
	private Context context;

	public ListAdapter(ArrayList<Music> arr, Context context) {
		super();
		this.arr = arr;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arr.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arr.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			LayoutInflater inflater = LayoutInflater.from(context);
			View v = inflater.inflate(R.layout.listadapter, null);
			TextView tv1 = (TextView) v.findViewById(R.id.text1);
			TextView tv2 = (TextView) v.findViewById(R.id.text2);
			tv1.setText(arr.get(position).getTitle());
			long dur = (arr.get(position).getDuration() / 1000);
	

			int minute = (int) (dur / 60);
			int hour = minute / 60;
			int second = (int) (dur % 60);
			minute %= 60;

			tv2.setText((hour < 10 ? "0" + hour : hour + "") + ":"
					+ (minute < 10 ? "0" + minute : minute + "") + ":"
					+ (second < 10 ? "0" + second : second + ""));
			return v;
		
		}
		return convertView;
	}

}
